package app.beit.fintrack.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

public class StringUtils {

	private static final DecimalFormat DF = new DecimalFormat("#,##0.00");
	
	public static String nullToEmpty(final String value){
		String val = "";
		if(value == null || value.equalsIgnoreCase("null")){
			return val;
		}
		
		return value;
	}

	public static BigDecimal nullToZero(final BigDecimal value){		
		return value == null ? new BigDecimal(0) : value;
	}
	
	public static String currencyFormat(final BigDecimal value){
		return DF.format(value != null ? value : 0);
	}
	
	public static String toTimeFormat(final String time){
		if(time == null){
			return "";
		}
		final String s1 = time.substring(0, 2);
		final String s2 = time.substring(2, 4);
		return s1 + ":" + s2;
	}
	
	public static String checkDate(final Date date){
		return "" + (date == null ? "" : date);
	}
	
	public static String currencyFormat(final Double value){
		return DF.format(value != null ? value : 0);
	}
	
	public static String zeroToEmpty(final String value){
		return value.equalsIgnoreCase("0") || value.equalsIgnoreCase("0.00")? "" : value; 
	}
}
